
const jwt = require("jsonwebtoken")
const secret="console.log('nihao')"
// 生产token
function createToken(info) {
    let token = jwt.sign(info, secret, {
        //Token有效时间 单位s
        expiresIn: 60 * 60 * 24
    })
    return token
}
// 验证token
function verifyToken(token) {
    console.log(token)
    return new Promise((resolve, reject) => {
        jwt.verify(token, secret, (error, result) => {
            if (error) {
                reject(error)
            } else {
                resolve(result)
            }
        })
    })
}

module.exports = {
    createToken,
    verifyToken
}